package com.sell.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.sell.entity.Members;
import com.sell.mapper.MembersMapper;
import com.sell.util.Pager;

@Service("membersService")
public class MembersServiceImpl implements MembersService {
	@Resource
	private MembersMapper membersMapper;
	/**
	 * 获取所有会员对象
	 */
	public List<Members> getAllMembers(Integer typeid,Integer num,String name, Pager pager) throws Exception {
		Map map=new HashMap();
		int startRow=(pager.getPageNo()-1)*pager.getPageSize();
		int pageSize= pager.getPageSize();
		map.put("num", num);
		map.put("typeid", typeid);
		map.put("name", name);
		map.put("startRow",startRow);
		map.put("pageSize",pageSize);
		List<Members> members=membersMapper.getAllMembers(map);
		if(members.size()>0){
			return members;
		}
		return null;
	}
    /**
     * 根据ID获取会员对象
     */
	public Members getMemberByid(Integer membersid){
      Members mem=membersMapper.getMemberByid(membersid);
		return mem;
	}
     /**
      * 添加会员对象
      */
	public int addMember(Members member) throws Exception {
		int num=membersMapper.insertMember(member);
		return num;
	}
    /**
     * 更新会员消费
     */
	public int updateMember(Double totalmoney,Integer integral,Integer membersid) throws Exception {
		int num=membersMapper.updateMember(totalmoney, integral, membersid);
		return num;
	}
    /**
     * 删除会员对象
     */
	public int deleteMember(Integer membersid) {
		int num=membersMapper.deleteMember(membersid);
		return num;
	}
	/**
	 * 获取记录数
	 */
	public int getAllCount(Integer typeid,Integer num,String name) {
		Map map=new HashMap();
		map.put("typeid", typeid);
		map.put("num", num);
		map.put("name", name);
		int i=membersMapper.getCount(map);
		return i;
	}
	public Members getBycardid(String cardid) {
		Members mem=membersMapper.getBycardid(cardid);
		return mem;
	}
	public void updatetypeid(Integer typeid,Integer membersid) throws Exception {
		membersMapper.updatetypeid(typeid, membersid);
	}
	public int updateAll(Members members) throws Exception {
		int num=membersMapper.updateAll(members);
		return num;
	}
	
}
